if exists (SELECT * from dbo.sysobjects WHERE id = object_id(N'[dbo].[vw_plants_distributions]') AND OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[vw_plants_distributions]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

/***********************************************************************
* vw Name: dbo.vw_plants_distributions
* Created: 20101112, RGM
* Purpose: listar el total de lo etiquetado por OC para cada Planta
*
* Modified: yyyymmdd, user, data
*
* HistoryDate.
* yyyymmdd User, data
* 
* Note: nothing
* 
***********************************************************************/
CREATE VIEW dbo.vw_plants_distributions AS
SELECT pod.purchase_order_version_id, p.plant_id, SUM(pod.quantity) quantity
	FROM purchases_orders_labeled_distributions pod, 
		plants_versions pv, plants p
	WHERE pod.plant_version_id = pv.plant_version_id
		AND pv.plant_id = p.plant_id
	GROUP BY pod.purchase_order_version_id, p.plant_id

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

